﻿/***************************************************************
	Thay đổi thiết kế bảng kiểm kê
****************************************************************/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_tblKiemKe_tblTon]') AND parent_object_id = OBJECT_ID(N'[dbo].[tblKiemKe]'))
ALTER TABLE [dbo].[tblKiemKe] DROP CONSTRAINT [FK_tblKiemKe_tblTon]
GO

/****** Object:  Table [dbo].[tblKiemKe]    Script Date: 05/29/2014 15:18:38 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tblKiemKe]') AND type in (N'U'))
DROP TABLE [dbo].[tblKiemKe]
GO
CREATE TABLE [dbo].[tblKiemKe](
	[ID_KiemKe] [int] IDENTITY(1,1) NOT NULL,
	[DotKiemKe] [int] NULL,
	[ID_MatHang] [int] NULL,
	[SLKKOld] [float] NULL,
	[SLLTang] [float] NULL,
	[SLGiam] [float] NULL,
	[SLSS] [float] NULL,
	[SLKK] [float] NULL,
	[SLThua] [float] NULL,
	[SLThieu] [float] NULL,
	[SLCCL1] [float] NULL,
	[SLCCL2] [float] NULL,
	[SLCCL3a] [float] NULL,
	[SLCCL3b] [float] NULL,
	[SLKhoBo] [float] NULL,
	[SLKhoDV] [float] NULL,
	[SLCSSX] [float] NULL,
	[SLDieuDi] [float] NULL,
	[SLThanhLy] [float] NULL,
	[GhiChu] [nvarchar](100) NULL,
 CONSTRAINT [PK_tblKiemKe] PRIMARY KEY CLUSTERED 
(
	[ID_KiemKe] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'1: Đợt 1/1, 2: Đợt 1/7' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tblKiemKe', @level2type=N'COLUMN',@level2name=N'DotKiemKe'
GO

ALTER TABLE [dbo].[tblKiemKe]  WITH CHECK ADD  CONSTRAINT [FK_tblKiemKe_tblTon] FOREIGN KEY([ID_MatHang])
REFERENCES [dbo].[tblTon] ([ID_MatHang])
ON UPDATE CASCADE
ON DELETE CASCADE
GO

ALTER TABLE [dbo].[tblKiemKe] CHECK CONSTRAINT [FK_tblKiemKe_tblTon]
GO

/***********************************************************************************
Bỏ bảng chi tiết kiểm kê
***********************************************************************************/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_tblCTKiemKeCCL_tblCCL]') AND parent_object_id = OBJECT_ID(N'[dbo].[tblCTKiemKeCCL]'))
ALTER TABLE [dbo].[tblCTKiemKeCCL] DROP CONSTRAINT [FK_tblCTKiemKeCCL_tblCCL]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_tblCTKiemKeCCL_tblKiemKe]') AND parent_object_id = OBJECT_ID(N'[dbo].[tblCTKiemKeCCL]'))
ALTER TABLE [dbo].[tblCTKiemKeCCL] DROP CONSTRAINT [FK_tblCTKiemKeCCL_tblKiemKe]
GO

/****** Object:  Table [dbo].[tblCTKiemKeCCL]    Script Date: 05/29/2014 15:20:45 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tblCTKiemKeCCL]') AND type in (N'U'))
DROP TABLE [dbo].[tblCTKiemKeCCL]
GO
